import random
from django.http import JsonResponse
from rest_framework.views import  APIView
from database import models
from django.db.models import Sum





class Echarts3(APIView):

    def get(self, request):

        data = {}

        try:

            x_list = []
            y_list = []

            res_obj = models.Total.objects.values("province").distinct()
            for datas in res_obj:
                if datas.get('province') != None:
                    x_list.append(datas.get('province'))
                    y_list.append(models.Total.objects.filter(province=datas.get('province')).count())

            data['x_list'] = x_list
            data['y_list'] = y_list

            return JsonResponse(data)

        except Exception as e:
            print(e)
            data['code'] = 444
            return JsonResponse(data)



